package com.darren.archive.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.darren.framework.entity.BaseEntity;
import com.darren.framework.utils.Constant;
import org.hibernate.annotations.ResultCheckStyle;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.List;

@Entity
@Table(name = Constant.TABLE_NAME_PREV + "function")
@org.hibernate.annotations.Table(appliesTo = Constant.TABLE_NAME_PREV + "function", comment = "系统功能/菜单表")
@SQLDelete(sql = "update " + Constant.TABLE_NAME_PREV + "function set is_delete = true,version=version+1 where id=? and version=?", check = ResultCheckStyle.COUNT)
@Where(clause = " is_delete  = false ")
public class SysFunction extends BaseEntity implements Serializable {


    private static final long serialVersionUID = -2015125588403190052L;

    @Column(name = "parent_id", columnDefinition = "bigint not null default 0 comment '上级功能/菜单  id'")
    private Long parentId;

    @Column(name = "function_name", columnDefinition = "varchar(50) not null comment '功能/菜单  名称'")
    private String functionName;

    @Column(name = "description", columnDefinition = "varchar(255) comment '功能/菜单 描述'")
    private String description;

    @Column(name = "href", columnDefinition = "varchar(255) comment '访问目标'")
    private String href;

    @Column(name = "target", columnDefinition = "varchar(20) default '' comment '打开方式。如_blank'")
    private String target;

    @Column(name = "permission", columnDefinition = "varchar(128) default '' comment '权限标识。Shiro使用，用于控制权限'")
    private String permission;

    @Column(name = "icon", columnDefinition = "varchar(128) default '' comment '图标'")
    private String icon;

    @Column(name = "is_enable", columnDefinition = "tinyint unsigned DEFAULT '1' COMMENT '是否启用。1 启用，0 禁用'")
    private Boolean enable = true;

    @Column(name = "display_sequence", columnDefinition = "varchar(10) default '100000' comment '显示顺序'")
    private String displaySequence;

    @Transient
    private List<SysFunction> children;

    @Transient
    @JSONField(serialize = false)
    private Boolean hasChildren = false;


    public List<SysFunction> getChildren() {
        return children;
    }

    public void setChildren(List<SysFunction> children) {
        this.children = children;
    }

    public Boolean getHasChildren() {
        return (children == null || children.size() == 0)?false:true;
    }

    public void setHasChildren(Boolean hasChildren) {
        this.hasChildren = hasChildren;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getFunctionName() {
        return functionName;
    }

    public void setFunctionName(String functionName) {
        this.functionName = functionName;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getHref() {
        return href;
    }

    public void setHref(String href) {
        this.href = href;
    }

    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = target;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public Boolean isEnable() {
        return enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    public String getDisplaySequence() {
        return displaySequence == null ? "100000":displaySequence;
    }

    public void setDisplaySequence(String displaySequence) {
        this.displaySequence = displaySequence;
    }
}
